﻿namespace WMS6.BLL
{
    using System;
    using System.Collections.Generic;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.IDAL;
    using WMS6.DALFactory;

    public class GlobalSettingBLL
    {
        private static readonly ICommonMethodDA commonMethod = DataAccess.CreateCommonMethod();
        private List<string> dataBaseID;
        private static readonly IGlobalSettingDA globalSettingDA = DataAccess.CreateGlobalSettingDA();

        public GlobalSettingBLL()
        {
            this.dataBaseID = new List<string> { "SYSADM." };
        }

        public GlobalSettingBLL(string currentWH)
        {
            if (!string.IsNullOrEmpty(currentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(currentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001");
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002");
            }
        }

        public List<GlobalSettingInfo> GetALLGlobalSetting()
        {
            List<GlobalSettingInfo> GlobalSettingList = null;
            try
            {
                GlobalSettingList = globalSettingDA.GetALLGlobalSetting();
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return GlobalSettingList;
        }

        public string UpdateGlobalSetting(GlobalSettingInfo globalSettingInfo)
        {
            string strTemp = string.Empty;
            try
            {
                if (globalSettingDA.UpdateGlobalSetting(globalSettingInfo) > 0)
                {
                    strTemp = globalSettingInfo.GlobalSettingID + "更新成功！";
                }
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return strTemp;
        }
    }
}

